<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.3.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.3.3/themes/icon.css">
<script type="text/javascript" src="jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript" src="jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">

	var bs = '${param.bs}' ? '${param.bs}' : '文章类别'; 

	var url;
	
	$(function(){
		$("#dg2").datagrid({
			onDblClickRow:function(rowIndex,rowData){
				chooseRole();
			}
		});
	})
	
	function searchList(){
		$('#dg').datagrid('load',{
			typename:$("#s_typename").val(),
		});
	}
	
	function openAddDialog(){
		$("#dlg").dialog("open").dialog("setTitle","添加信息");
		url="types/save.do?";
		$('#bs').val("${param.bs}");
	}
	
	function openModifyDialog(){
		var selectedRows=$("#dg").datagrid('getSelections');
		if(selectedRows.length!=1){
			$.messager.alert('系统提示','请选择一条要编辑的数据！');
			return;
		}
		var row=selectedRows[0];
		$("#dlg").dialog("open").dialog("setTitle","修改信息");
		$("#fm").form("load",row);
		url="types/save.do?id="+row.id;
	}
	
	function saveBean(){
		$("#fm").form("submit",{
			url:url,
			onSubmit:function(){
				return $(this).form("validate");
			},
			success:function(result){
				console.log(result);
				result = eval("("+result+")");
				if(result.code != "0"){
					$.messager.alert('系统提示',"<font color=red>"+result.errMsg+"</font>");
					return;
				}else{
					$.messager.alert('系统提示','保存成功');
					closeAddDialog();
					$("#dg").datagrid("reload");
				}
			}
		});
	}
	
	function closeAddDialog(){
		$("#dlg").dialog("close");
		$("#fm").form('clear');
	}
	
	
	function deleteObj(){
		var selectedRows=$("#dg").datagrid('getSelections');
		if(selectedRows.length==0){
			$.messager.alert('系统提示','请选择要删除的数据！');
			return;
		}
		var strIds=[];
		for(var i=0;i<selectedRows.length;i++){
			strIds.push(selectedRows[i].id);
		}
		var ids=strIds.join(",");
		$.messager.confirm("系统提示","您确认要删除这<font color=red>"+selectedRows.length+"</font>条数据吗？",function(r){
			if(r){
				$.post("types/delete.do",{ids:ids},function(result){
					if(result.code == 0){
						$.messager.alert('系统提示',"您已成功删除数据！");
						$("#dg").datagrid("reload");W
					}else{
						$.messager.alert('系统提示',result.errorMsg);
					}
				},"json");
			}
		});
	}
</script>
</head>
<body style="margin: 1px;">
<table id="dg" title="列表" class="easyui-datagrid" fitColumns="true" 
    pagination="true" rownumbers="true" url="types/list.do?bs=${param.bs}" fit="true" toolbar="#tb">
    <thead>
    	<tr>
    		<th field="cb" checkbox="true" align="center"></th>
    		<th field="id" width="150" align="center">编号</th>
			<th field="typename" width="200" align="center">类别名称</th>
			<th field="bs" width="200" align="center">大类型</th>
			<th field="createdate" width="200" align="center">创建日期</th>
			
    	</tr>
    </thead>
</table>
<div id="tb">
	<div>
		<a href="javascript:openAddDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
		<a href="javascript:openModifyDialog()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
		<a href="javascript:deleteObj()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
	</div>
	<div>
		&nbsp;类别名称：&nbsp;<input type="text" name="s_typename" id="s_typename" size="20" onkeydown="if(event.keyCode==13) searchList()"/>
		<a href="javascript:searchList()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
	</div>
</div>

<div id="dlg" class="easyui-dialog" style="width: 570px;height: 350px;padding: 10px 20px"
  closed="true" buttons="#dlg-buttons">
  <form id="fm" method="post">
  	<table cellspacing="5px;">
  		<tr>
			<td>类别名称：</td>
			<td><input type="text" id="typename" name="typename" class="easyui-validatebox" required="true"/></td>
		</tr>
			<tr>
			<td>大类型：</td>
			<td><input value="${param.bs}" type="text" id="bs" name="bs" class="easyui-validatebox" required="true"/></td>
		</tr>
			
  		
  	</table>
  </form>
</div>

<div id="dlg-buttons">
	<a href="javascript:saveBean()" class="easyui-linkbutton" iconCls="icon-ok" >保存</a>
	<a href="javascript:closeAddDialog()" class="easyui-linkbutton" iconCls="icon-cancel" >关闭</a>
</div>

</body>
</html>